var ws, state, cur_page = 1,
	title;
var resArry = [];
var noMore = false;
var app = angular.module("newsApp", []);
app.controller("newsController", function($scope, $http) {
	$scope.initView = function() {
		console.log(cur_page);
		if(noMore) { return; } //没有数据就返回出来      
		plus.nativeUI.showWaiting('加载中...');
		$http({
			method: 'post',
			url: apiRoot,
			data: {
				action: 'Trade.category',
				type: state,
				page: cur_page
			}
		}).then(function successCallback(response) {
			plus.nativeUI.closeWaiting();
			if(response.data.data == undefined) {
				$scope.not_more = 1;
				noMore = true;
				return;
			}
			resArry.push(response.data.data);
			$scope.goods_data = resArry //最新内容数据 
		}, function errorfunction(e) {
			plus.nativeUI.closeWaiting();
			console.log(JSON.stringify(e));
		})
	}

	//推荐商品
	$scope.Traderecommend = function(uid, type, id) {
		plus.nativeUI.showWaiting('加载中...');
		plus.webview.create('goods_detail.html', 'goods_detail.html', {}, { gUid: uid, type: type, gId: id }).show('pop-in');
		plus.nativeUI.closeWaiting();
	}

	//最新商品
	$scope.Tradenews = function(uid, type, id) {
		plus.nativeUI.showWaiting('加载中...');
		plus.webview.create('goods_detail.html', 'goods_detail.html', {}, { gUid: uid, type: type, gId: id }).show('pop-in');
		plus.nativeUI.closeWaiting();

	}

	//热门商品
	$scope.Tradehot = function(uid, type, id) {
		plus.webview.create('goods_detail.html', 'goods_detail.html', {}, { gUid: uid, type: type, gId: id }).show('pop-in');
	}
})

document.addEventListener("plusready", function() {
	ws = plus.webview.currentWebview();
	appElement = document.querySelector('[ng-controller=newsController]');
	$scope = angular.element(appElement).scope();
	state = ws.state;
	title = ws.title;
	$('.mui-title').html(title);
	$scope.initView();
	$scope.$apply();
})